package huu.phong.youtube;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JLabel;

public class VideoCanvas extends Canvas{

	private static final long serialVersionUID = 6555717656046840353L;
	private Dimension dimension;
	private JLabel label;
	
	public VideoCanvas(){
		super();
		label = new JLabel("", JLabel.CENTER);
		label.setVerticalAlignment(JLabel.CENTER);
		setTitle("YouTube Player", "© 2013 by Nguyễn Hữu Phong");
	}
	
	public void paint(Graphics g){
//		super.paint(g);
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
		g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,	RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
		dimension = getSize();
		label.setSize(dimension);
		label.setPreferredSize(dimension);
		label.setMaximumSize(dimension);
		label.setMinimumSize(dimension);
		label.setForeground(Color.WHITE);
		label.paint(g2);
	}
	
	public void setTitle(String title, String description){
		label.setText("<html><div style='padding: 0px 10px 0px 10px; text-align: center; font-size: 30px;'>" + title + "</div><div style='padding: 20px 10px 0px 10px; text-align: center; font-size: 15px;'>" + description + "</div></html>");
		repaint();
	}
}
